package controller

import (
	"github.com/gin-gonic/gin"
	"shop-common/library/serializer"
	"shop-common/utils/contextArgs"
	"shop-common/utils/queryWrapper"
	"shop-service/business"
)

type AreaController struct {
}

// @Tags 省市区
// @description: 通过父级id获取区域列表
// @Summary 通过父级id获取区域列表
// @function: ListByPid
// @Accept  json
// @Produce  json
// @Param pid query int true "父id" default(0)
// @Success 200 {object} string "{"code":0," result":{}, "message":"操作成功", "time":1618493448}"
// @Router /p/area/listByPid [get]
func (c *AreaController) ListByPid(ctx *gin.Context) {
	pid, err := contextArgs.GetUriIntQuery(ctx, "pid")
	if err != nil {
		serializer.Fail(ctx, err.Error())
		return
	}

	areas, err := business.ServiceImpl().AreaService.Find(ctx, queryWrapper.Eq("parent_id", pid))
	if err != nil {
		serializer.Fail(ctx, serializer.PublicQueryErr)
		return
	}

	serializer.SuccessData(ctx, "", areas)
}
